package com.learn.annotation_config.component.beans.service;

import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * @Component：如果不指定value属性，默认将首字母小写后的类名作为该Bean的名称
 * @Scope：用于指定Bean的作用范围，取值singleton/prototype
 * @Lazy：用于指定Bean实例化时机，取值false/true/default
 * @PostConstruct：用于标记Bean实例化后执行的初始化方法
 * @PreDestroy：用于标记Bean实例销毁前执行的方法
 */
@Component
@Scope("singleton")
@Lazy(false)
public class UserServiceImpl implements UserService {
    public UserServiceImpl() {
        System.out.println("实例化UserServiceImpl");
    }
    
    @PostConstruct
    public void init() {
        System.out.println("实例化UserServiceImpl后");
    }
    
    @PreDestroy
    public void destroy() {
        System.out.println("销毁UserServiceImpl前");
    }
}
